from pyecharts import options as opts
from pyecharts.charts import Bar
import pandas as pd
def draw_bar(all_list):
    print("开始绘图")
    # 0碑林、1莲湖、2未央、3雁塔、4灞桥、5长安、6临潼、7新城区、8西咸新区（西安）
    attr = ["碑林", "莲湖", "未央", "雁塔", "灞桥", "长安", "临潼", "新城区", "西咸新区"]
    v0 = all_list[0]
    v1 = all_list[1]
    v2 = all_list[2]
    v3 = all_list[3]

    bar = (
        Bar()
        .add_xaxis(attr)
        .add_yaxis("最大值", v0, label_opts=opts.LabelOpts(is_show=True))
        .add_yaxis("最小值", v1, label_opts=opts.LabelOpts(is_show=True))
        .add_yaxis("平均值", v2, label_opts=opts.LabelOpts(is_show=True))
        .add_yaxis("中位数", v3, label_opts=opts.LabelOpts(is_show=True))
        .set_global_opts(
            title_opts=opts.TitleOpts(title="西安市租房租金概况"),
            xaxis_opts=opts.AxisOpts(min_="dataMin", max_="dataMax"),
            datazoom_opts=[opts.DataZoomOpts()],
        )
    )
    bar.render("./page_all/render.html", width="1000px")  # 在这里设置图表的宽度
    print("结束绘图1")


 # 定义数据
    data = {
        "地区": ["碑林", "莲湖", "未央", "雁塔", "灞桥", "长安", "临潼", "新城区", "西咸新区"],
        "最大值": v0,
        "最小值": v1,
        "平均值": v2,
        "中位数": v3
    }

    # 创建 DataFrame
    df = pd.DataFrame(data)

    # 打印数据
    print(df)

    print("结束绘制数据视图2")
